package io.renren.controller;

import io.renren.entity.MedicalEnjoyManagementEntity;
import io.renren.entity.SysUserEntity;
import io.renren.service.MedicalEnjoyManagementService;
import io.renren.utils.PageUtils;
import io.renren.utils.QueryAuthority;
import io.renren.utils.R;
import io.renren.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 医疗险享受管理
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-11 11:56:34
 */
@RestController
@RequestMapping("medicalenjoymanagement")
public class MedicalEnjoyManagementController {
	@Autowired
	private MedicalEnjoyManagementService medicalEnjoyManagementService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("medicalenjoymanagement:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        QueryAuthority query = new QueryAuthority(params);

		List<MedicalEnjoyManagementEntity> medicalEnjoyManagementList = medicalEnjoyManagementService.queryList(query);
		int total = medicalEnjoyManagementService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(medicalEnjoyManagementList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("medicalenjoymanagement:info")
	public R info(@PathVariable("id") Integer id){
		MedicalEnjoyManagementEntity medicalEnjoyManagement = medicalEnjoyManagementService.queryObject(id);
		
		return R.ok().put("medicalEnjoyManagement", medicalEnjoyManagement);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("medicalenjoymanagement:save")
	public R save(@RequestBody MedicalEnjoyManagementEntity medicalEnjoyManagement){
		SysUserEntity user= (SysUserEntity) ShiroUtils.getSubject().getSession().getAttribute("user");
		medicalEnjoyManagement.setCusername(user.getUsername());
		medicalEnjoyManagement.setCdate(new Date());
		medicalEnjoyManagement.setCdeptId(user.getDeptNo());
		medicalEnjoyManagementService.save(medicalEnjoyManagement);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("medicalenjoymanagement:update")
	public R update(@RequestBody MedicalEnjoyManagementEntity medicalEnjoyManagement){
		medicalEnjoyManagementService.update(medicalEnjoyManagement);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("medicalenjoymanagement:delete")
	public R delete(@RequestBody Integer[] ids){
		medicalEnjoyManagementService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
